<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"PD-4-2");
mysql_select_db($database_con_gl, $con_gl);
$query_klas = "SELECT id, kelompok FROM gl_kelompok ORDER BY kelompok ASC";
$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());
$row_klas = mysql_fetch_assoc($klas);
$totalRows_klas = mysql_num_rows($klas);

$colname_edit = "-1";
if (isset($_GET['id'])) {
  $colname_edit = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_con_gl, $con_gl);
$query_edit = sprintf("SELECT * FROM gl_kelompok WHERE id = %s", $colname_edit);
$edit = mysql_query($query_edit, $con_gl) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
$totalRows_edit = mysql_num_rows($edit);

mysql_select_db($database_con_gl, $con_gl);
$query_ak1 = "SELECT gl_akun.akun, gl_akun.id, gl_klas.kd as kd_klas FROM gl_akun, gl_klas WHERE gl_klas.tipe='3' AND gl_akun.klasifikasi =  gl_klas.kd";
$ak1 = mysql_query($query_ak1, $con_gl) or die(mysql_error());
$row_ak1 = mysql_fetch_assoc($ak1);
$totalRows_ak1 = mysql_num_rows($ak1);

mysql_select_db($database_con_gl, $con_gl);
$query_ak2 = "SELECT gl_akun.akun, gl_akun.id, gl_klas.kd as kd_klas FROM gl_akun, gl_klas WHERE gl_klas.tipe='4' AND gl_akun.klasifikasi =  gl_klas.kd";
$ak2 = mysql_query($query_ak2, $con_gl) or die(mysql_error());
$row_ak2 = mysql_fetch_assoc($ak2);
$totalRows_ak2 = mysql_num_rows($ak2);

mysql_select_db($database_con_gl, $con_gl);
$query_ak3 = "SELECT gl_akun.akun, gl_akun.id, gl_klas.kd as kd_klas FROM gl_akun, gl_klas WHERE gl_klas.tipe='5' AND gl_akun.klasifikasi =  gl_klas.kd";
$ak3 = mysql_query($query_ak3, $con_gl) or die(mysql_error());
$row_ak3 = mysql_fetch_assoc($ak3);
$totalRows_ak3 = mysql_num_rows($ak3);
?>
<link type="text/css" rel="stylesheet" href="css/jquery.wysiwyg.css" />
<script type="text/javascript" src="js/jquery.wysiwyg.js"></script>
<script type="text/javascript">
$(document).ready(function() {

	$().ajaxStart(function() {
		$('#loading').show();
		$('#result').hide();
	}).ajaxStop(function() {
		$('#loading').hide();
		$('#result').fadeIn('slow');
	});

	$('#edit').submit(function() {
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data) {
				$('#result').html(data);
			}
		})
		return false;
	});
  $('#result').click(function(){
  $(this).hide();
  });
})
$(function()
  {
	  $('#keterangan').wysiwyg();
  });
</script>
<div id="loading" style="display:none;"><img src="images/loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<h1>Edit Kelompok Barang/Jasa</h1>
<form action="proses/kelompokbarang.php?act=edit" method="POST" name="edit" id="edit" >
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Jenis Kelompok: </td>
      <td bgcolor="#FFFFFF"><table width="200" cellpadding="0" cellspacing="0">
          <tr>
            <td width="83">Barang</td>
            <td width="105">Jasa</td>
          </tr>
          <tr>
            <td><input name="RadioGroup2" type="radio" value="1" <?php if($row_edit['jenis']==1) { ?>checked="checked"<?php } ?> /></td>
            <td><label>
              <input type="radio" name="RadioGroup2" value="2" <?php if($row_edit['jenis']==2) { ?>checked="checked"<?php } ?>/>
            </label></td>
          </tr>
      </table></td>
    </tr>
    <tr valign="top">
      <td width="20%" align="right" bgcolor="#FFFFFF">Nama Kelompok* : </td>
      <td width="80%" bgcolor="#FFFFFF"><label>
        <input name="kelompok" type="text" id="kelompok" value="<?php echo $row_edit['kelompok']; ?>" size="30" maxlength="100" />
      </label></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Keterangan : </td>
      <td bgcolor="#FFFFFF"><label>
      <textarea name="keterangan" cols="85" rows="5" id="keterangan"><?php echo $row_edit['keterangan']; ?></textarea>
      <input name="id" type="hidden" id="id" value="<?php echo $row_edit['id']; ?>" />
      </label></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">GL Akun : </td>
      <td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr>
            <td><label>
              <select name="persediaan" id="persediaan">
                <option value="">Akun Persediaan</option>
                <?php if($totalRows_ak1 > 0) { ?>
                <?php
do {  
?>
                <option value="<?php echo $row_ak1['id']?>" <?php if($row_ak1['id']==$row_edit['ak_sedia']) { ?>selected="selected"<?php } ?>><?php echo $row_ak1['id']?>-<?php echo $row_ak1['akun']?></option>
                <?php
} while ($row_ak1 = mysql_fetch_assoc($ak1));
  $rows = mysql_num_rows($ak1);
  if($rows > 0) {
      mysql_data_seek($ak1, 0);
	  $row_ak1 = mysql_fetch_assoc($ak1);
  }
?>
                <?php } ?>
              </select>
            </label></td>
            <td><label>
              <select name="pembelian" id="pembelian">
                <option value="">Akun HPP</option>
                <?php if($totalRows_ak2 > 0) { ?>
                <?php
do {  
?>
                <option value="<?php echo $row_ak2['id']?>" <?php if($row_ak2['id']==$row_edit['ak_beli']) { ?>selected="selected"<?php } ?>><?php echo $row_ak2['id']?>-<?php echo $row_ak2['akun']?></option>
                <?php
} while ($row_ak2 = mysql_fetch_assoc($ak2));
  $rows = mysql_num_rows($ak2);
  if($rows > 0) {
      mysql_data_seek($ak2, 0);
	  $row_ak2 = mysql_fetch_assoc($ak2);
  }
?>
                <?php } ?>
              </select>
            </label></td>
            <td><label>
              <select name="penjualan" id="penjualan">
                <option value="">Akun Penjualan</option>
                <?php if($totalRows_ak3 > 0) { ?>
                <?php
do {  
?>
                <option value="<?php echo $row_ak3['id']?>" <?php if($row_ak3['id']==$row_edit['ak_jual']) { ?>selected="selected"<?php } ?>><?php echo $row_ak3['id']?>-<?php echo $row_ak3['akun']?></option>
                <?php
} while ($row_ak3 = mysql_fetch_assoc($ak3));
  $rows = mysql_num_rows($ak3);
  if($rows > 0) {
      mysql_data_seek($ak3, 0);
	  $row_ak3 = mysql_fetch_assoc($ak3);
  }
?>
                <?php } ?>
              </select>
            </label></td>
          </tr>
      </table></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Dijual : </td>
      <td bgcolor="#FFFFFF"><table width="200" cellpadding="0" cellspacing="0">
          <tr>
            <td width="83"> Ya </td>
            <td width="105"><label> Tidak</label></td>
          </tr>
          <tr>
            <td><input name="RadioGroup1" type="radio" value="1" <?php if($row_edit['jual']==1) { ?>checked="checked"<?php } ?>/></td>
            <td><label>
              <input type="radio" name="RadioGroup1" value="2" <?php if($row_edit['jual']==2) { ?>checked="checked"<?php } ?>/>
            </label></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF">Metode HPP : </td>
      <td bgcolor="#FFFFFF"><label>
        <select name="metode" id="metode">
          <option value="1" <?php if($row_edit['metode']==1) { ?>selected="selected"<?php } ?>>FIFO</option>
          <option value="2" <?php if($row_edit['metode']==2) { ?>selected="selected"<?php } ?>>LIFO</option>
          <option value="3" <?php if($row_edit['metode']==3) { ?>selected="selected"<?php } ?>>Average</option>
        </select>
      </label></td>
    </tr>
    
    <tr>
      <td align="left" bgcolor="#FFFFFF"><em>*Harus diisi</em></td>
      <td bgcolor="#FFFFFF"><label>
        <input name="Save" type="submit" id="Save" value="Simpan" />
        </label>
          <label>
          <input type="button" name="Button" value="Batal" onClick="javascript:history.go(-1);">
        </label></td>
    </tr>
  </table>
</form>
